package com.lzs.bootsafety.common.util.easyexcel.Converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.lzs.bootsafety.common.util.easyexcel.enums.GenderEnum;

/**
 * @Author  zhanshi Liu
 * @Date    2020/04/03
 * @Website www.jhmsona.cn
 * @Desc 性别转换
 */
public class GenderConverter implements Converter<String>  {
    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return GenderEnum.of(cellData.getStringValue()).getLabel();

    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new CellData(GenderEnum.of(value).getValue());
    }
}
